package com.hsp.Demo_03_object;

public class Demo_11 {
    public static void main(String[] args) {
        Person11 person1 = new Person11("小明", 18);
        Person11 person2 = new Person11("小明", 18);
        if(person1.compareTo2(person2)){
            System.out.println("person1 和 person2 是同一个人");
        }else{
            System.out.println("person1 和 person2 不是同一个人");
        }
    }
}

class Person11{

    String name;
    int age;

    public Person11(){}

    public Person11(String name, int age){
        this.name = name;
        this.age = age;
    }

    public boolean compareTo(Person11 person){
        if(person.name == null || person.name == ""||this.name==null || this.name == ""){
            return false;
        }
        if(this.name.equals(person.name) && this.age == person.age){
            return true;
        }else{
            return false;
        }
    }

    public boolean compareTo2(Person11 person){
       /* if(person.name == null || person.name == ""||this.name==null || this.name == ""){
            return false;
        }*/
        return this.name.equals(person.name) && this.age == person.age;
    }
}
